<?php

namespace Api\Openapi;

/**
 * Class Exception
 * @package Api\Openapi
 * @description openapi异常类，错误码以305开头
 * @link http://wiki.i.beebank.com:8090/pages/viewpage.action?pageId=4980809
 */
class Exception extends \S\Exception {

    const DEFAULT_ERR_CODE = "3050099";  //未配置的错误码默认转换为此错误码
    const DEFAULT_ERR_MSG = '系统繁忙，请稍后再试。';  //默认错误消息

    /**
     * @var array 错误码转换配置
     */
    private static $_error_mapping = array(
        "5001201" => array("code" => "3051201", "msg" => "当前应用未配置此简讯服务"),
        "5001202" => array("code" => "3021202", "msg" => "当前应用未配置默认简讯服务"),
    );

    public function __construct($message = "", $code = 0, \Exception $previous = null) {
        if (isset(self::$_error_mapping[$code])) {
            $err_code = self::$_error_mapping[$code]["code"];
            $err_msg = empty(self::$_error_mapping[$code]["msg"]) ? $message : self::$_error_mapping[$code]["msg"];
        } else {
            $err_code = self::DEFAULT_ERR_CODE;
            $err_msg = empty($message) ? self::DEFAULT_ERR_MSG : $message;
        }

        parent::__construct($err_msg, $err_code, $previous);
    }

}